import { ctrlMgr } from "../Manager/CtrlMgr";
import { eventMgr } from "../Manager/EventMgr";
import { BaseTimer } from "./BaseTimer";


export abstract class BaseCtrl {

    //初始化
    protected abstract onInit(): void;
    //事件监听
    protected abstract onCustomEvent(): void;
    //销毁
    protected abstract onDispose(): void;
    //跨天
    protected abstract onNewDay(): void;
    // 游戏切入后台调用
    protected abstract onBackground(): void;
    // 游戏回到前台调用
    protected abstract onForeground(): void;

    private _timer: BaseTimer = null
    protected get Timer(): BaseTimer {
        return this._timer
    }

    // 框架调用 销毁 
    public readonly dispose = () => {
        this.onDispose()
        this.Timer.stopAllTimer()
        eventMgr.targetOff(this)
    }

    // 框架调用 跨天
    public readonly newDay = () => {
        this.onNewDay()
    }

    // 框架调用 游戏切入后台调用
    public readonly background = () => {
        this.onBackground()
    }

    // 框架调用 游戏回到前台调用
    public readonly foreground = () => {
        this.onForeground()
    }

    constructor() {
        ctrlMgr.addCtrl(this)
        this.onInit()
    }

    init() {
        this.onInit()
        this.onCustomEvent()
    }
}